package com.smartpro.mis.modular.business.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.smartpro.mis.core.base.controller.BaseController;
import com.smartpro.mis.rest.modular.auth.controller.dto.ResponseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
//import com.smartpro.mis.core.log.LogObjectHolder;
import com.smartpro.mis.modular.system.model.Position;
import com.smartpro.mis.modular.business.service.IPositionService;

import java.util.Map;

/**
 * 岗位控制器
 *
 * @author mengiy
 * @Date 2019-05-07 21:49:43
 */
@RestController
@RequestMapping("/api/service/position")
public class PositionController extends BaseController {


    @Autowired
    private IPositionService positionService;

    /**
     * 获取岗位列表
     */
    @ApiOperation(value = "获取岗位列表",notes ="全部查询" )
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    @RequiresAuthentication
    public Object list() {
        return new ResponseBean(200,"operation success",positionService.selectList(null));
    }



    /**
     * 条件查询岗位列表
     */
    @ApiOperation(value = "条件查询岗位列表",notes ="条件查询" )
    @ApiImplicitParam(name = "conditionMap",value = "包含元素：Position的属性字段",required = true,dataType = "JSONObject")
    @RequestMapping(value = "/multiQuery",method = RequestMethod.POST)
    @ResponseBody
    @RequiresAuthentication
    public Object multiQuery(@RequestBody JSONObject queryContion) {
        Map condtion = JSONObject.parseObject(queryContion.toJSONString(),Map.class);
        return new ResponseBean(200,"query success",positionService.selectByMap(condtion));
    }

    /**
     * 新增岗位
     */
    @ApiOperation(value = "新增岗位",notes = "添加岗位")
    @ApiImplicitParam(name = "position",value = "岗位的详细信息",required = true,dataType = "JSONObject")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    @RequiresAuthentication
    public Object add(@RequestBody Position position) {
        positionService.insert(position);
        EntityWrapper<Position> queryWrapper = new EntityWrapper<Position>();
        queryWrapper.setEntity(position);
        return new ResponseBean(200,"add success",positionService.selectOne(queryWrapper));
    }

    /**
     * 删除岗位
     */
    @RequestMapping(value = "/delete/{positionId}",method = RequestMethod.GET)
    @ApiOperation(value = "删除岗位",notes = "根据岗位编号进行删除")
    @ApiImplicitParam(name = "positionID",value = "岗位编号",required = true,dataType = "Integer")
    @ResponseBody
    @RequiresAuthentication
    public Object delete(@PathVariable("positionId") Integer positionId) {
        Position position = positionService.selectById(positionId);
        positionService.deleteById(positionId);
        return new ResponseBean(200,"delete success",position);
    }

    /**
     * 修改岗位
     */
    @ApiOperation(value = "修改岗位",notes = "修改岗位信息")
    @ApiImplicitParam(name = "position",value = "岗位信息",required = true,dataType = "Position")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    @RequiresAuthentication
    public Object update(@RequestBody Position position) {
        positionService.updateById(position);
        return new ResponseBean(200,"update success",positionService.selectById(position.getPositionID()));
    }

    /**
     * 岗位详情
     */
    @ApiOperation(value = "查看岗位信息",notes = "根据岗位编号进行查询")
    @ApiImplicitParam(name = "positionID",value = "岗位编号",required = true,dataType = "Integer")
    @RequestMapping(value = "/detail/{positionId}",method = RequestMethod.GET)
    @ResponseBody
    @RequiresAuthentication
    public Object detail(@PathVariable("positionId") Integer positionId) {
        return new ResponseBean(200,"view success",positionService.selectById(positionId));
    }
}
